package com.songlanyun.config;


import com.songlanyun.common.utils.sensi.SensitiveFilter;
import com.songlanyun.modules.sensitive.dao.SystemSensitiveWordDao;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.util.List;

/**
 * 敏感词配置
 */
@Configuration
public class SensiConfig {

    @Resource
    private SystemSensitiveWordDao systemSensitiveWordDao;

    @Bean
    public SensitiveFilter sensitiveFilter() {
        // 使用默认单例（加载默认词典）
        SensitiveFilter filter = SensitiveFilter.DEFAULT;
        //将数据库中所有附加敏感词存入filter
        List<String> texts = systemSensitiveWordDao.getSources();
        if (texts != null) {
            texts.forEach(v -> {
                filter.put(v);
            });
        }
        return filter;
    }
}
